const changeColumns = [
  { type: 'index', width: 50, align: 'center' },
  { title: '变化类型', key: 'changeType', ellipsis: true },
  { title: '记录数', width: 80, key: 'count', ellipsis: true },
  { title: '面积(㎡)', key: 'area', ellipsis: true },
];
const relChangeColumns = [
  { type: 'index', width: 50, align: 'center' },
  { title: '标识码', key: 'changeType', ellipsis: true },
  { title: 'over_标识码', key: 'count', ellipsis: true },
  { title: '一级分类', key: 'area', ellipsis: true },
  // over_一级分类,权属性质,权属性质,over_权属性质,图斑面积,over_图斑面积,地类编码
];
export default {
  name: 'ShowTable',
  data() {
    return {
      serviceType: '',
    };
  },
  methods: {
    //wfs获取表格列
    getTableColumns(data) {
      let cols = [];
      if (data.features.length == 0) {
        return [];
      }
      cols.push({
        type: 'index',
        width: 50,
        align: 'center',
      });
      Object.keys(data.features[0].properties).forEach(p => {
        cols.push({ title: p, key: p, width: 160, maxWidth: 200, ellipsis: true });
      });
      return cols;
    },
    //wfs获取数据行
    getTableRows(data) {
      let rows = data.features.map(p => {
        return {
          ...p.properties,
          id: p.id,
          serviceType: this.serviceType,
        };
      });
      return rows;
    },
    // 统计分析获取数据
    getChangeTableColumns(data) {
      let cols = [];
      if (data.length == 0) {
        return [];
      }
      cols = changeColumns;
      return cols;
    },
    getChangeTableData(data) {
      let rows = data.map(p => {
        return {
          changeType: `${p.fromDl}变${p.toDl}`,
          count: p.count,
          area: p.area,
          serviceType: 'statDltbChanges',
        };
      });
      return rows;
    },
    // 详细分析获得数据
    getRelColumns(data) {
      let cols = [];
      if (Object.keys(data).length == 0) {
        return [];
      }
      cols.push({
        type: 'index',
        width: 50,
        align: 'center',
      });
      Object.keys(data.arr1.length !== 0 ? data.arr1[0] : data.arr2[0]).forEach(p => {
        cols.push({
          title: p,
          key: p,
          width: 160,
          maxWidth: 200,
          ellipsis: true,
        });
      });
      return cols;
    },
    getRelRows(data) {
      let rows = [];
      data['arr2'].forEach(p => {
        rows.push({
          ...p,
        });
      });
      return rows;
    },
  },
};
